<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">

    <meta charset="utf-8">

    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">

    <meta content="yes" name="apple-mobile-web-app-capable">

    <meta content="black" name="apple-mobile-web-app-status-bar-style">

    <meta content="telephone=no" name="format-detection">

    <title>登录</title>

    <link href="style/login.css" rel="stylesheet" type="text/css" />

    <link href="css/vant.css" rel="stylesheet" type="text/css" />

    <script src="js/jquery-3.3.1.min.js"></script>

    <script src="js/vue.js"></script>

    <script src="js/axios.js"></script>

    <script src="js/qs.js"></script>

    <script src="js/MD5.js"></script>

    <script src="js/vant.js"></script>

    <script type="text/javascript" src="js/js.js"></script>

</head>

<body>

    <div id="app">

        <div class="ve_title">{{title}}</div>

        <div v-show="isShow">

            <div class="main">

                <div class="login_txt">登录</div>

                <div class="login_type_o">

                    <span style="background-image:url(images/phone1.png); color:#0092fd" id="ck_phone"
                        onclick="check_login('phone')">短信登录</span>

                    <span style="background-image:url(images/user.png)" id="ck_user"
                        onclick="check_login('user')">密码登录</span>

                </div>

                <input ref="login_type" id="login_type" type="hidden" value="phone" />

                <input ref="send" id="send" type="hidden" value="60" />

                <div class="login_o" id="phone_login">

                    <div class="login_text">手机号</div>

                    <div class="login_input">

                        <input v-model="from1.phone" style="font-size: 14px;" id="phone" type="text" class="phone_input"
                            onkeyup="this.value=this.value.replace(/\D/g,'');" maxlength="11"
                            onafterpaste="this.value=this.value.replace(/\D/g,'')" placeholder="请输入手机号码" />

                    </div>

                    <div class="login_text" style="margin-top:10px">短信验证码</div>

                    <div class="login_input_code" style="padding-bottom:3px;">

                        <input v-model="from1.sms_code" style="font-size: 14px;width: 50%;" id="code" type="text"
                            class="code_input" placeholder="请输入验证码" onkeyup="this.value=this.value.replace(/\D/g,'');"
                            maxlength="6" onafterpaste="this.value=this.value.replace(/\D/g,'')" style="width:55%;" />

                        <div class="code_getcode" @click="get_sms_code()" style="float:right;">获取验证码</div>

                    </div>

                </div>

                <div class="login_o" id="user_login" style="display:none">

                    <div class="login_text">手机号</div>

                    <div class="login_input">

                        <input v-model="from.username" style="font-size: 14px;" id="uphone" type="text"
                            class="phone_input" onafterpaste="this.value=this.value.replace(/\D/g,'')"
                            placeholder="请输入手机号码" />

                    </div>

                    <div class="login_text" style="margin-top:10px">密码</div>

                    <div class="login_input_code" style="padding-bottom:3px;">

                        <input v-model="from.password" style="font-size: 14px;" id="upassword" type="password"
                            class="code_input" placeholder="请输入密码" />

                    </div>

                    <a href="login_set.html" class="login_text"
                        style="margin-top:10px; font-size:13px; text-align:right;"> 设置密码</a>

                </div>

                <div class="login_but_o" @click="gologins()">登录</div>

                <!-- <div class="wxlogin"><img src="images/wx2.png" @click="wxlogin" /></div>	 -->

            </div>

        </div>

        <div v-show="!isShow" class="main">

            <div class="ve_title">请先绑定手机号码</div>

            <div class="login_o" id="phone_login">

                <div class="login_text">手机号</div>

                <div class="login_input">

                    <input v-model="from1.phone" style="font-size: 14px;" id="phone" type="text" class="phone_input"
                        onkeyup="this.value=this.value.replace(/\D/g,'');" maxlength="11"
                        onafterpaste="this.value=this.value.replace(/\D/g,'')" placeholder="请输入手机号码" />

                </div>

                <div class="login_text" style="margin-top:10px">短信验证码</div>

                <div class="login_input_code" style="padding-bottom:3px;">

                    <input v-model="from1.sms_code" style="font-size: 14px;width: 50%;" id="code" type="text"
                        class="code_input" placeholder="请输入验证码" onkeyup="this.value=this.value.replace(/\D/g,'');"
                        maxlength="6" onafterpaste="this.value=this.value.replace(/\D/g,'')" style="width:55%;" />

                    <div class="code_getcode" @click="get_sms_code()" style="float:right;">获取验证码</div>

                </div>

            </div>

            <div class="login_but_o" @click="bingPhone">绑定手机号</div>

        </div>

    </div>

</body>

<script>

    var app = new Vue({

        el: '#app',

        data: {
            sending: false,
            sendData: {},

            isShow: true,

            title: '',

            helloData: {},

            from: {

                username: '',

                password: '',

                action: "adviser",

                vid: ''

            },

            from1: {

                sms_code: "",

                phone: "",

                action: "adviser",

                vid: ''

            },

            vid: '',

            wxinfo: '',

            Openid: '',

            Unionid: '',

            VidPhone: '',

            state: ''

        },

        created() {

            this.setCanS()

        },

        methods: {

            setCanS() {

                //获取登录状态

                let timeLoc = new Date()

                // let isBeOverdue;

                // if(localStorage.getItem('adviserTime') == null){

                //     isBeOverdue = 0;

                // }else{

                //     isBeOverdue=Date.parse(localStorage.getItem('adviserTime'));

                // }

                let isBeOverdue = Date.parse(localStorage.getItem('adviserTime'));

                let Request = new Object()

                Request = GetRequest()

                this.vid = Request['vid']

                this.wxinfo = Request['wxinfo']

                if (this.vid == undefined || this.vid == '' || this.vid == null) {

                    this.vid = ''

                } else {

                    sessionStorage.setItem('vid', this.vid)

                }

                this.from.vid = this.vid

                this.from1.vid = this.vid

                this.getSname()

                if (this.wxinfo != '' && this.wxinfo != null && this.wxinfo != undefined) {

                    this.getWxlogin()

                }

                console.log(timeLoc.getTime() - isBeOverdue > 0)

                if (this.vid == '') {

                    //判断是否过期

                    if (isBeOverdue != undefined && isBeOverdue != '' && isBeOverdue != null && isNaN(isBeOverdue) != true) {

                        //判断是否过期

                        if (timeLoc.getTime() - isBeOverdue > 0) {

                            //过期

                        } else {

                            //未过期

                            let vid = localStorage.getItem('adviservid')

                            let Gtoken = localStorage.getItem('adviserGtoken')

                            sessionStorage.setItem('logo', '0')

                            sessionStorage.setItem('token', Gtoken)

                            sessionStorage.setItem('vid', vid)

                            let type = "logo"

                            sessionStorage.setItem('type', type)

                            window.location.href = 'index.html?vid=' + vid + '&type=' + type + ''

                        }

                    }

                } else {

                    if (isBeOverdue != null && isBeOverdue != undefined && isBeOverdue != '' && isNaN(isBeOverdue) != true) {

                        let vid = localStorage.getItem('adviservid')

                        if (this.vid != vid) {



                        } else {

                            //判断是否过期

                            if (timeLoc.getTime() - isBeOverdue > 0) {

                                //过期



                            } else {

                                //未过期

                                let vid = localStorage.getItem('adviservid')

                                let Gtoken = localStorage.getItem('adviserGtoken')

                                sessionStorage.setItem('logo', '0')

                                sessionStorage.setItem('token', Gtoken)

                                sessionStorage.setItem('vid', vid)

                                let type = "logo"

                                sessionStorage.setItem('type', type)

                                window.location.href = 'index.html?vid=' + vid + '&type=' + type + ''

                            }

                        }

                    }

                }

            },

            getSname() {

                getVs()

                const params = {

                    vid: sessionStorage.getItem('vid', this.vid)

                }

                sessionStorage.setItem('logo', '1')

                axios.get('/mobileapi/login_staff.php?act=login', { params: params }).then(data => {

                    console.log(data.data)

                    let { msg, code, user } = data.data

                    if (code != 200) {

                        window.vant.Toast.fail(msg)

                    } else {

                        data = data.data

                        this.title = data.data.Vname

                    }

                }).catch(function (error) {

                    console.log(error);



                });

            },

            //登录

            gologins() {

                sessionStorage.setItem('logo', '1')

                if (this.$refs.login_type.value == 'user') {

                    var obj = this;

                    let password = md5(this.from.password)

                    password = md5(password)

                    console.log(password)

                    let from = {

                        username: this.from.username,

                        password: password,

                        action: "adviser",

                        vid: sessionStorage.getItem('vid')

                    }

                    from = JSON.stringify(from)

                    let sign = md5(from)

                    let params = {

                        from: from,

                        sign: sign

                    }

                    axios.post('/mobileapi/login_staff.php?act=logingo',

                        Qs.stringify(params)).then(data => {

                            let { msg, code, user } = data.data

                            if (code !== 200) {

                                window.vant.Toast.fail(msg)

                            } else {

                                data = data.data

                                sessionStorage.setItem('vxPhone', data.data.Phone)

                                if (data.data.login_from == 'ADVISER') {

                                    if (data.data.login_type == '2') {

                                        sessionStorage.setItem('logo', '1')

                                        sessionStorage.setItem('token', data.data.Gtoken)

                                        let venueset_list = JSON.stringify(data.data.venueset_list)

                                        sessionStorage.setItem("venueset_list", venueset_list)

                                        //跳转到选择场馆页面

                                        window.location.href = 'selectShop.html?vid=' + this.vid + ''

                                    } else {

                                        sessionStorage.setItem('logo', '0')

                                        sessionStorage.setItem('token', data.data.Gtoken)

                                        this.vid = data.data.Vid

                                        sessionStorage.setItem('vids', this.vid)

                                        sessionStorage.setItem('vid', this.vid)

                                        let type = "logo"

                                        localStorage.setItem('adviser', '1')

                                        localStorage.setItem('adviservid', data.data.Vid)

                                        localStorage.setItem('adviserGtoken', data.data.Gtoken)

                                        let timeLoc = new Date()

                                        localStorage.setItem('adviserTime', new Date(timeLoc.getTime() + 365 * 24 * 60 * 60 * 1000))

                                        sessionStorage.setItem('type', type)

                                        window.location.href = 'index.html?vid=' + this.vid + '&type=' + type + ''

                                    }

                                } else {

                                    window.vant.Toast("该账号无法登陆会籍顾问端")

                                }

                            }



                        }).catch(function (error) {

                            console.log(error);

                        });

                } else {

                    this.from1.vid = sessionStorage.getItem('vid')

                    let from = this.from1
                    from["data"] = this.sendData;

                    from = JSON.stringify(from)

                    let sign = md5(from)

                    let params = {

                        from: from,

                        sign: sign

                    }

                    axios.post('/mobileapi/login_staff.php?act=sms_login', Qs.stringify(params)).then(data => {

                        let { msg, code } = data.data;

                        if (code != 200) {

                            window.vant.Toast.fail(msg)

                        } else {

                            data = data.data

                            sessionStorage.setItem('vxPhone', data.data.Phone)

                            if (data.data.login_from == 'ADVISER') {

                                if (data.data.login_type == '2') {

                                    sessionStorage.setItem('logo', '1')

                                    sessionStorage.setItem('token', data.data.Gtoken)

                                    let venueset_list = JSON.stringify(data.data.venueset_list)

                                    sessionStorage.setItem("venueset_list", venueset_list)

                                    //跳转到选择场馆页面

                                    window.location.href = 'selectShop.html?vid=' + this.vid + ''

                                } else {

                                    sessionStorage.setItem('logo', '0')

                                    sessionStorage.setItem('token', data.data.Gtoken)

                                    this.vid = data.data.Vid

                                    sessionStorage.setItem('vids', this.vid)

                                    sessionStorage.setItem('vid', this.vid)

                                    let type = "logo"

                                    localStorage.setItem('adviser', '1')

                                    localStorage.setItem('adviservid', data.data.Vid)

                                    localStorage.setItem('adviserGtoken', data.data.Gtoken)

                                    let timeLoc = new Date()

                                    localStorage.setItem('adviserTime', new Date(timeLoc.getTime() + 365 * 24 * 60 * 60 * 1000))

                                    sessionStorage.setItem('type', type)

                                    window.location.href = 'index.html?vid=' + this.vid + '&type=' + type + ''

                                }

                            } else {

                                window.vant.Toast("该账号无法登陆会籍顾问端")

                            }

                        }



                    }).catch(function (error) {

                        console.log(error);

                    });

                }

            },

            //获取手机验证码

            get_sms_code() {

                var send = parseInt(this.$refs.send.value);

                if (!isPoneAvailable(this.from1.phone)) {

                    window.vant.Toast.fail("请输入正确的手机号")

                    return false;

                }

                const params = {

                    phone: this.from1.phone

                }
                if (this.sending) {
                    return;
                }

                if (send == 60) {
                    this.sending = true;
                    var that = this;
                    axios.post('/mobileapi/login_staff.php?act=getsms', Qs.stringify(params)).then(function (response) {

                        if (response.data.code == "200") {
                            that.sendData = response.data.data;
                            console.log(that.sendData);
                            window.vant.Toast.success("短信已发，请注意查收")

                        } else {
                            that.sending = false;
                            window.vant.Toast.fail(response.data.msg)



                        }

                    }).catch(function (error) {

                        console.log(error)

                        window.vant.Toast.fail("短信发送失败！请确认手机号是否正确。");

                    })

                    var set = setInterval(function () {

                        var send_t = --send;

                        $(".code_getcode").html("" + send_t + "秒");

                        $("#send").val(--send_t)

                    }, 1000);

                    setTimeout(function () {
                        that.sending = false;

                        $(".code_getcode").html("重新获取");

                        $("#send").val(60)

                        clearInterval(set);

                    }, 60000);

                }

            },



            //验证手机号正不争取

            isPoneAvailable($poneInput) {

                var myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;

                if (!myreg.test($poneInput)) {

                    return false;

                } else {

                    return true;

                }

            },

            //微信登录

            wxlogin() {

                window.location.href = 'http://wx.bj.guanjialc.com/api/wxlogin.php?Assystem=3fc62b5aec87be2e4dd05a531412cc4f&Venid=' + this.vid + '&backurl=http%3a%2f%2ffitness.guanjialc.com%2fphone%2fadviser%2flogin.html%3fvid=' + this.vid + ''

            },

            //获取code然后跳去接口登录

            getWxlogin() {

                let params = {

                    vid: sessionStorage.getItem('vid'),

                    wxinfo: this.wxinfo,

                    action: "adviser"

                }

                axios.get('/mobileapi/login_staff_wx_b.php?act=login',

                    { params: params }).then(data => {

                        console.log(data.data)

                        let { msg, code } = data.data

                        if (code !== 200) {

                            window.vant.Toast.fail(msg)

                        } else {

                            console.log(data.data)

                            data = data.data

                            //console.log(data)

                            sessionStorage.setItem('vxPhone', data.data.Phone)

                            if (data.data.login_from == 'ADVISER') {

                                if (data.data.login_type == '2') {

                                    sessionStorage.setItem('logo', '0')

                                    sessionStorage.setItem('token', data.data.Gtoken)

                                    let venueset_list = JSON.stringify(data.data.venueset_list)

                                    sessionStorage.setItem("venueset_list", venueset_list)

                                    //跳转到选择场馆页面

                                    window.location.href = 'selectShop.html?vid=' + this.vid + ''



                                } else if (data.data.login_type == '1') {

                                    this.vid = data.data.Vid

                                    sessionStorage.setItem('logo', '0')

                                    sessionStorage.setItem('token', data.data.Gtoken)

                                    sessionStorage.setItem('vids', this.vid)

                                    sessionStorage.setItem('vid', this.vid)

                                    let type = "logo"

                                    sessionStorage.setItem('type', type)

                                    let timeLoc = new Date()

                                    localStorage.setItem('adviserTime', new Date(timeLoc.getTime() + 365 * 24 * 60 * 60 * 1000))

                                    window.location.href = 'index.html?vid=' + this.vid + '&type=' + type + ''

                                } else {

                                    //绑定手机号弹出手机号和验证码

                                    this.Openid = data.data.Openid

                                    if (data.data.Unionid) {

                                        this.Unionid = data.data.Unionid

                                    } else {

                                        this.Unionid = ''

                                    }

                                    this.VidPhone = data.data.Vid

                                    this.isShow = false

                                }

                            } else {

                                window.vant.Toast("该账号无法登陆会籍顾问端")

                            }

                        }

                    }).catch(function (error) {

                        console.log(error);

                    });

            },

            //绑定手机号跳转首页

            bingPhone() {

                let from = {

                    phone: this.from1.phone,

                    sms_code: this.from1.sms_code,

                    vid: this.VidPhone,

                    login_from: "ADVISER",

                    openid: this.Openid,

                    unionid: this.Unionid

                }

                from = JSON.stringify(from)

                let sign = md5(from)

                let params = {

                    from: from,

                    sign: sign

                }

                axios.post('/mobileapi/login_staff_wx_b.php?act=bing_phone',

                    Qs.stringify(params)).then(data => {

                        let { msg, code } = data.data

                        if (code !== 200) {

                            window.vant.Toast.fail(msg)

                        } else {

                            data = data.data

                            if (data.data.login_from == 'ADVISER') {

                                if (data.data.login_type == '2') {

                                    sessionStorage.setItem('logo', '1')

                                    sessionStorage.setItem('token', data.data.Gtoken)

                                    let venueset_list = JSON.stringify(data.data.venueset_list)

                                    sessionStorage.setItem("venueset_list", venueset_list)

                                    //跳转到选择场馆页面

                                    window.location.href = 'selectShop.html?vid=' + this.vid + ''

                                    sessionStorage.setItem('vxPhone', this.from1.phone)

                                } else {

                                    sessionStorage.setItem('logo', '0')

                                    sessionStorage.setItem('token', data.data.Gtoken)

                                    this.vid = data.data.Vid

                                    sessionStorage.setItem('vids', this.vid)

                                    sessionStorage.setItem('vid', this.vid)

                                    let type = "logo"

                                    sessionStorage.setItem('type', type)

                                    window.location.href = 'index.html?vid=' + this.vid + '&type=' + type + ''

                                }

                            } else {

                                window.vant.Toast("该账号无法登陆教练端")

                            }

                        }

                    }).catch(function (error) {

                        console.log(error);

                    });

            }

        }

    })

</script>

</html>